package krt.wid.gslzs.activity;

import android.view.KeyEvent;

import java.util.Timer;
import java.util.TimerTask;

import krt.wid.gslzs.R;
import krt.wid.gslzs.base.BaseActivity;

/**
 * @author Marcus
 * @package krt.wid.gslzs.activity
 * @description
 * @time 2018/5/12
 */

public class EntMainActivity extends BaseActivity {

    private boolean isExit;

    @Override
    public int bindLayout() {
        return R.layout.activity_ent_main;
    }

    @Override
    public void initView() {
        getSupportFragmentManager().beginTransaction().add(R.id.content, GovMainFragment.newInstance(getIntent().getStringExtra("entCode"))).commitAllowingStateLoss();
    }

    @Override
    public void loadData() {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            exitBy2Click();
        }
        return true;
    }

    private void exitBy2Click() {
        Timer tExit = null;
        if (isExit == false) {
            isExit = true; // 准备退出
            showToast("再按一次退出程序");
            tExit = new Timer();
            tExit.schedule(new TimerTask() {
                @Override
                public void run() {
                    isExit = false; // 取消退出
                }
            }, 2 * 1000); // 如果2秒钟内没有按下返回键，则启动定时器取消掉刚才执行的任务

        } else {
            finish();
            System.exit(0);
        }
    }
}
